<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root">

    </div>
</body>
<script src="../react@17.js"></script>
<script src="../react-dom@17.js"></script>
<script src="../babel.js"></script>
<script type="text/babel">
    /* 
    非父子通信-状态提升:中间人模式
    子 => 父 => 子
    */
    class App extends React.Component{
        state={
            num:""
        }
        render(){
            return (
                <div>
                    <One num={this.state.num}/>
                    <Two getNum={(num)=>{
                        console.log(num,"父组件")
                        this.setState({
                            num
                        })
                    }}/>
                </div>
            )
        }
    }
    class One extends React.Component{
        render(){
            return (
                <div>
                   <h1>one组件----{this.props.num}</h1> 
                </div>
            )
        }
    }
    class Two extends React.Component{
        state = {
            num:100
        }
        render(){
            return (
                <div>
                    <h1>two组件</h1>
                    <button onClick={()=>{
                        this.setState((state)=>{
                            return {
                                num:state.num +1
                            }
                        },()=>{
                            this.props.getNum(this.state.num);
                        })
                       
                    }}>向另一个子组件传值</button>
                </div>
            )
        }
    }
    ReactDOM.render(<App/>,document.getElementById("root"))
</script>
</html>